package work;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.TreeSet;

/**
 * @auther Macrydy
 * @date 2020/7/16 19:05
 */
public class ComparableTest {
    public static void main(String[] args) throws Exception {
        //创建一个可自动排序的treeset集合
        TreeSet set = new TreeSet();
        //读数据
        BufferedReader br = new BufferedReader(new FileReader("F:\\1.txt"));
        String b;
        //把读到的数据添加到set集合中
        while ((b=br.readLine())!=null){
            String[] split = b.split("");
            for (String s : split) {
                set.add(s);
            }
        }

//        System.out.println(set);
        //创建写出对象
        BufferedWriter bw = new BufferedWriter(new FileWriter("F:\\2.txt"));
        StringBuilder sb = new StringBuilder();

        for (Object o : set) {
            sb.append(o);
        }

        //写入排序后的数据
        bw.write(sb.toString());
        //关流
        bw.close();
        br.close();

    }
}
